package com.flute.icrawler.check.checker;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RowsCompare  implements ICompare {

	private static Logger logger = LoggerFactory.getLogger("RowsCompare");
	@Override
	public boolean compare(File targetFile, File sourceFile) {
		boolean isSame = false ;
		List<String> array_Target = null;
		List<String> array_Source = null;
		try {
			array_Target = transFormFiletoArray(targetFile);
			 array_Source = transFormFiletoArray(sourceFile);
		} catch (IOException e) {
			logger.error("compare error" + e);
		}
		
		if(array_Target.size() != array_Source.size()){
			return isSame;
		}else{
			for(int i=0;i<array_Target.size();i++){
				  if(!array_Target.get(i).equals(array_Source.get(i))){
					  return isSame;
				  }
			}
		}
		return true;
	}
	private List<String> transFormFiletoArray(File file) throws IOException{
		List<String> a_Strs = new ArrayList<String>();
		BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
		String str_a; 
		while((str_a=br.readLine())!=null){
			if(!str_a.equals("")) a_Strs.add(str_a);
		}
		return a_Strs;
	}

}
